import { controller, httpGet as get, httpPost as post } from "inversify-express-utils";
import { DemoServices } from "./demo.services";
import { inject } from 'inversify'
import { Request, Response } from "express";

/**
 * ## Demo 模块控制器
 * - 根路径：/demo
 */

@controller('/demo')
export class Demo {

  constructor(
    @inject(DemoServices) private readonly demo: DemoServices
  ) { }

  /**
   * ## 请求示例
   * - 请求方式：GET
   * - 请求路径：/demo/get
   */
  @get('/get')
  public async get(req: Request, res: Response) {
    let result = this.demo.get()
    res.cc('ok', { data: result }, 200)
  }

  /**
   * ## 请求示例
   * - 请求方式：POST
   * - 请求路径：/demo/post
   */
  @post('/post')
  public async post(req: Request, res: Response) {
    let result = this.demo.post(req.body)
    res.cc('ok', { data: result }, 200)
  }
}
